/**
 * @author 王琪 <wangqi@huizhaofang.com>
 * @since 2020-03-08
 */
package com.diploma.project.aiqiyi.controller;

import com.diploma.project.aiqiyi.CommonResponse;
import com.diploma.project.aiqiyi.common.annotation.AuthControl;
import com.diploma.project.aiqiyi.dao.UserVideoDao;
import com.diploma.project.aiqiyi.dao.VideoDao;
import com.diploma.project.aiqiyi.dto.VideoDetailDto;
import com.diploma.project.aiqiyi.model.UserVideo;
import com.diploma.project.aiqiyi.model.Video;
import com.diploma.project.aiqiyi.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;
    @Autowired
    private VideoDao videoDao;
    @Autowired
    private UserVideoDao uservideoDao;



    @GetMapping("videos/{category}/")
    public CommonResponse<List<Video>> getVideosByCategory(@PathVariable("category") Integer category) {
        return CommonResponse.success(videoService.queryVideosByCategory(category));
    }


    @GetMapping("videos/")
    public CommonResponse<List<Video>> getVideos(String keyword) {
        return CommonResponse.success(videoService.queryVideos(keyword));
    }

    /**
     * 获取视频详情以及推荐列表
     * @param id
     * @return
     */
    @GetMapping("video/{id}/")
    public CommonResponse<VideoDetailDto> getOne(@PathVariable("id") Integer id) {
        return CommonResponse.success(videoService.queryVideoDetail(id));
    }



    //评论显示
    @GetMapping("video/showremark/")
    public CommonResponse<List<UserVideo>> queryShowRemark( Integer id) {
        return CommonResponse.success(videoService.queryRemark(id));

    }

    /**
     * 收藏视频、购买视频
     * @param id
     * @return
     */
    @AuthControl
    @PostMapping("video/collect/")
    public CommonResponse collect(Integer id, Integer type, String beizhu) {
        videoService.saveUserVideo(id, type, beizhu);
        return CommonResponse.ok();
    }

    /**
     * 获取用户收藏、用户关注、历史记录
     * @param type
     * @return
     */
    @AuthControl
    @GetMapping("user/videos/{type}/")
    public CommonResponse<List<Video>> getUserVideos(@PathVariable("type") Integer type) {
        return CommonResponse.success(videoService.queryUserVideos(type));
    }

    @AuthControl
    @DeleteMapping("user/videos/")
    public CommonResponse removeUserHistory() {
        videoService.deleteUserHistory();
        return CommonResponse.ok();
    }

}
